C     Program EX_0601.FOR
C     Listing 12F - see documentation in TUTOR.SSS

$include:'SSSF1.H'

      subroutine prime
$include:'SSSF2.H'
      call INIQUE(1, 3, 1)
      call SIMEND(24.0)
      call CREATE(0.0, 0)
      call inista(1,'Cost                 ',0, 0, 0, 0)
      call SETQDC(1, 'SVF     ')
      return
      end
 
      Program EX_0601
$include:'SSSF2.H'
      integer ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server, ecode
      data  ARRIVL/1/, STARTA/2/, ENDACT/3/, NEXTAC/4/
      data  id/0/, server/1/
 
      call prime
 
   99 ecode = NEXTEV()
      if (ecode.gt.0) then
        goto (101, 102, 103, 104) ecode
 
C ARRIVL
  101   continue
        id = id + 1
        call CREATE(EX(1.0), id)
        call SETA(1, T())
        call SETA(2, 1 + EX(2.0))
        call SETA(3, RN(.66667, .16667))
        call SCHED(0.0, NEXTAC, IDE())
        goto 99
 
C NEXTAC
  104   continue
        if (server.gt.0) then
          call SCHED(0.0, STARTA, IDE())
        else
          call QUEUE(1, A(3)/A(2))
        endif
        goto 99
 
C STARTA
  102   continue
        call SCHED(A(3), ENDACT, IDE())
        server = server - 1
        goto 99
 
C ENDACT
  103   continue
        call TALLY(1, (T() - A(1))*A(2))
        call DISPOS
        server = server + 1
        if (NQ(1).gt.0) then
          call REMVFQ(1, 1)
          call SCHED(0.0, STARTA, IDE())
        endif
        goto 99
 
      else
 
        call SUMRY(' ')
        stop 'End of simulation'
 
      endif
      end
